import {
    apiPath,
    apiUrl
} from '@/config/index'
import HTTP from '@/utils/request'

export const userLogin = (res) => {
    wx.request({
        url: apiUrl + apiPath + '/api/customer/login?code=' + res.code,
        method: 'POST',
        data: {
            code: res.code,
        },
        success: ({
            data
        }) => {
            if (data.code === 200) {
                wx.setStorageSync('token', data.data.token)
                wx.setStorageSync("userInfo", JSON.stringify(data.data.customer || {}))
                wx.setStorageSync('WX_CODE', res.code)
                wx.navigateBack()
            } else {
                wx.showToast({
                    title: data.msg,
                    icon: 'error',
                })
            }
        }
    })
}

const getUserInfo = () => {
    return HTTP.get({
        url: '/getInfo'
    })
}